using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using MonoTouch.Foundation;
using MonoTouch.ObjCRuntime;

namespace Cocos2D
{
	#region Camera
	
	partial class Camera
	{
		public void GetEye(out float x, out float y, out float z)
		{
			unsafe
			{
				fixed (float *xx = &x, yy = &y, zz = &z)
				{
					IntPtr pX = (IntPtr)xx;
					IntPtr pY = (IntPtr)yy;
					IntPtr pZ = (IntPtr)zz;
					
					this.GetEye(pX, pY, pZ);
				}
			}
		}
		
		public void GetCenter(out float x, out float y, out float z)
		{
			unsafe
			{
				fixed (float *xx = &x, yy = &y, zz = &z)
				{
					IntPtr pX = (IntPtr)xx;
					IntPtr pY = (IntPtr)yy;
					IntPtr pZ = (IntPtr)zz;
					
					this.GetCenter(pX, pY, pZ);
				}
			}
		}
		
		public void GetUp(out float x, out float y, out float z)
		{
			unsafe
			{
				fixed (float *xx = &x, yy = &y, zz = &z)
				{
					IntPtr pX = (IntPtr)xx;
					IntPtr pY = (IntPtr)yy;
					IntPtr pZ = (IntPtr)zz;
					
					this.GetUp(pX, pY, pZ);
				}
			}
		}
	}
	
	#endregion
	
	#region Texture2D
	
	partial class Texture2D
	{
		public void SetTexParameters(ref TexParams texParams)
		{
			unsafe
			{
				fixed (TexParams *tp = &texParams)
				{
					IntPtr pParams = (IntPtr)tp;
					this.SetTexParameters(pParams);
				}
			}
		}
	}
	
	#endregion
	
	#region TextureAtlas
	
	partial class TextureAtlas
	{
		public void UpdateQuad(ref V3F_C4B_T2F_Quad quad, uint index)
		{
			unsafe
			{
				fixed (V3F_C4B_T2F_Quad *q = &quad)
				{
					IntPtr pQuad = (IntPtr)q;
					this.UpdateQuad(pQuad, index);
				}
			}
		}
		
		public void InsertQuad(ref V3F_C4B_T2F_Quad quad, uint index)
		{
			unsafe
			{
				fixed (V3F_C4B_T2F_Quad *q = &quad)
				{
					IntPtr pQuad = (IntPtr)q;
					this.InsertQuad(pQuad, index);
				}
			}
		}
		
		// TODO:
		// V3F_C4B_T2F_Quad *Quads (IntPtr Quads)
	}
	
	#endregion
	
	#region ObjCAction
	
	[Register("ObjCAction")]
	public class ObjCAction : NSObject
	{
		public static readonly Selector ActionSelector = new Selector("action:");
		internal static readonly Selector selInit = new Selector("init");
		
		private Action<NSObject> _action;
		
		public ObjCAction()
			: base(NSObjectFlag.Empty)
		{
			this.Handle = Messaging.IntPtr_objc_msgSend(this.Handle, selInit.Handle);
		}
		
		public ObjCAction(IntPtr handle)
			: base(handle)
		{
		}
		
		public ObjCAction(Action<NSObject> action)
			: this()
		{
			_action = action;
		}
		
		[Export("action:")]
		public void Action(NSObject sender)
		{
			_action(sender);
		}
	}
	
	#endregion
	
	#region MenuItem
	
	partial class MenuItem
	{
		private ObjCAction _action;
		
		public static MenuItem ItemWithAction(Action<NSObject> action)
		{
			return new MenuItem(action);
		}
		
		public MenuItem(ObjCAction action)
			: this(action, ObjCAction.ActionSelector)
		{
			_action = action;
		}
		
		public MenuItem(Action<NSObject> action)
			: this(new ObjCAction(action))
		{
		}
		
		public ObjCAction Action
		{
			get
			{
				return _action;
			}
			internal set
			{
				_action = value;
			}
		}
	}
	
	#endregion
	
	#region MenuItemFont
	
	partial class MenuItemFont
	{
		public static MenuItemFont ItemFromString(string text, Action<NSObject> action)
		{
			return new MenuItemFont(text, action);
		}
		
		public MenuItemFont(string text, ObjCAction action)
			: this(text, action, ObjCAction.ActionSelector)
		{
			this.Action = action;
		}
		
		public MenuItemFont(string text, Action<NSObject> action)
			: this(text, new ObjCAction(action))
		{
		}
	}
	
	#endregion
	
	#region Menu
	
	partial class Menu
	{
		public static Menu MenuWithItems(params MenuItem[] items)
		{
			Menu ret = default(Menu);
			IntPtr pNativeArr = Marshal.AllocHGlobal(items.Length * IntPtr.Size);
			
			for (int i = 1; i < items.Length; ++i)
			{
				Marshal.WriteIntPtr(pNativeArr, (i - 1) * IntPtr.Size, items[i].Handle);
			}
			Marshal.WriteIntPtr(pNativeArr, (items.Length - 1) * IntPtr.Size, IntPtr.Zero);
			
			ret = new Menu(items[0], pNativeArr);
			Marshal.FreeHGlobal(pNativeArr);
			
			return ret;
		}
	}
	
	#endregion*/
}
